-------------------------------------------------------------------------------------------
-- TRIGGER DELETE_CONTACT_STUDENTS (OK)
-------------------------------------------------------------------------------------------
CREATE TRIGGER DELETE_CONTACT_STUDENTS
	AFTER DELETE ON STUDENTS REFERENCING OLD AS OLD
    	FOR EACH ROW MODE DB2SQL
  			DELETE FROM CONTACTS 
  			WHERE ID_CONTACT = OLD.ID_CONTACT_STUDENT
;

-------------------------------------------------------------------------------------------
-- TRIGGER DELETE_CONTACT_PUBLISHERS (OK)
-------------------------------------------------------------------------------------------
CREATE TRIGGER DELETE_CONTACT_PUBLISHERS
	AFTER DELETE ON PUBLISHERS REFERENCING OLD AS OLD
    	FOR EACH ROW MODE DB2SQL
  			DELETE FROM CONTACTS WHERE ID_CONTACT = OLD.ID_CONTACT_PUBLISHER
;

-------------------------------------------------------------------------------------------
-- TRIGGER DELETE_LOANS_BOOKS (OK)
-------------------------------------------------------------------------------------------
CREATE TRIGGER DELETE_LOANS_BOOKS
	AFTER DELETE ON LOANS REFERENCING OLD AS OLD
    	FOR EACH ROW MODE DB2SQL
  	    	UPDATE EXEMPLARS 
  			SET EXEMPLARS.STATUS_EXEMPLAR = TRUE 
  			WHERE ID_EXEMPLAR = OLD.ID_EXEMPLAR_LOAN
;

-------------------------------------------------------------------------------------------
-- TRIGGER INSERT_LOANS_BOOKS (OK)
-------------------------------------------------------------------------------------------
CREATE TRIGGER INSERT_LOANS_BOOKS
	AFTER INSERT ON LOANS REFERENCING NEW AS NEW
    	FOR EACH ROW MODE DB2SQL
  			UPDATE EXEMPLARS 
  			SET EXEMPLARS.STATUS_EXEMPLAR = FALSE 
  			WHERE EXEMPLARS.ID_EXEMPLAR = NEW.ID_EXEMPLAR_LOAN
 ; 	 